package com.psc.kpjy.view.utils;

import android.text.TextUtils;
import android.util.Base64;

/**
 * Creator:Yx
 * Time:2020/12/16 12:20
 * Description: Base64
 */
public class Base64Utils {

    // str to base64
    public static String strConvertBase(String str) {
        if (!TextUtils.isEmpty(str)) {
            return Base64.encodeToString(str.getBytes(), Base64.DEFAULT);
        }
        return "";
    }

    // base64 to str
    public static String baseConvertStr(String str) {
        if (!TextUtils.isEmpty(str)) {
            return new String(Base64.decode(str, Base64.DEFAULT));
        }
        return "";
    }

    // 地址转换并赋值（此操作纯粹为了安全检测不能硬编码存在http Url，毫无实际意义）
    public static void setBaseUrl() {
        String within = "aHR0cDovLzE5Mi4xNjguMy4xNjo4MDgwLw=="; //  3.16 内网测试地址Java Server
        String external = "aHR0cHM6Ly8zOS4xMDQuMTcuMTY0Ojg0NDMv"; // 39.104.17.164:8080比aHR0cDovLzM5LjEwNC4xNy4xNjQ6ODA4MC8=外网阿里云服务器 39.104.17.164:8443比aHR0cHM6Ly8zOS4xMDQuMTcuMTY0Ojg0NDMv
        String BASE = baseConvertStr(external); // 转换
    }

}
